/*
The MIT License (MIT)

Copyright (c) 2014 Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#include "hhdTypes.h"
#include "hhdAssert.h"
#include <stdarg.h>
#include <stdio.h>

namespace hhd
{
	typedef uint32_t rtti_t;

	/// <summary>	Type ID structure that stores the individual and composite values that are used
	/// 			for Run-time type checking. 
	/// </summary>
	///
	/// <remarks>	baw, 1/29/2012. </remarks>

	struct TypeIDs
	{
		TypeIDs(rtti_t in_individual_id, ...);

		rtti_t individual_id;
		rtti_t composite_id;
	};

	uint32_t getNextPrime();

	/// <summary>	Is method. Used to check if a given object is of the queried type. </summary>
	///
	/// <remarks>	baw, 1/29/2012. </remarks>
	///
	/// <param name="in_object_instance">	The passed in object instance. </param>
	///
	/// <returns>	True if it is of the queried type, false otherwise. </returns>

	template <typename HaveType, typename QueryType>
	flag_t is(const HaveType& in_object_instance);

	/// <summary>	Is method. Used to check if a given object is of the queried type. </summary>
	///
	/// <remarks>	baw, 1/29/2012. </remarks>
	///
	/// <param name="in_object_pointer">	[in] If non-null, the passed in object pointer. </param>
	///
	/// <returns>	True if it is of the queried type, false otherwise. Also false if passed null. </returns>

	template <typename HaveType, typename QueryType>
	flag_t is( HaveType*const in_object_pointer);
}

#include "hhdTypeID.inl"

#define HHD_TYPE_ID_H()\
	private:\
		static hhd::TypeIDs _type_id;\
	public:\
		rtti_t objectIndividualID() const;\
		static rtti_t individualID();\
		static rtti_t compositeID();


#define HHD_TYPE_ID_CPP(DefinitionClass, ... /* Base Classes' IDs */)\
	hhd::TypeIDs DefinitionClass::_type_id((DefinitionClass::individualID()), ##__VA_ARGS__, 0);\
	rtti_t DefinitionClass::objectIndividualID() const { return _type_id.individual_id; }\
	rtti_t DefinitionClass::individualID() { return _type_id.individual_id ? _type_id.individual_id : (_type_id.individual_id = hhd::getNextPrime()); }\
	rtti_t DefinitionClass::compositeID() { return _type_id.composite_id; }
